﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;

namespace CoderJoe.Net
{
    private static class WebHelper
    {
        public static WebHeaderCollection GetHeaders(Uri url, TimeSpan timeout)
        {
            if(IsSupportedScheme(url) == false)
                    throw new ArgumentException("Uri scheme not supported");

            HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
            request.Timeout = timeout.Milliseconds;
            request.Method = "HEAD";

            using (HttpWebResponse response = (request.GetResponse() as HttpWebResponse))
            {
                return response.Headers;
            }
        }

        public static bool IsSupportedScheme(Uri url)
        {
            switch (url.Scheme)
            {
                case "http":
                case "https":
                    return true;
                default:
                    return false;
            }
        }
    }
}
